
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)


// import indexPage from '../view/index.vue'
// import loginPage from '../view/login.vue'


const routes = [
    { path: '/', redirect: '/login'},
    { 
      path: '/index', 
      component:() => import('../view/index.vue'),
      redirect: '/index/banners',
      meta: { title: '首页' },
      children:[
        {
          path: 'banners',
          meta: { title: '轮播图管理' }, 
          component:() => import('../view/shouye/banner.vue'),
          beforeEnter: (to, from,next) => {
            // reject the navigation
            next()
          },
        },
        {path: 'category',meta: { title: '分类管理' }, component:() => import('../view/shouye/category.vue') },
        {path: 'recomend',meta: { title: '为你推荐管理' }, component:() => import('../view/shouye/recomend.vue') },

      ]
    },
    { path: '/login', component:() => import('../view/login.vue') },
  ]

const router = new VueRouter({
    // 4. 内部提供了 history 模式的实现。为了简单起见，我们在这里使用 hash 模式。
    // history: VueRouter.createWebHashHistory(),
    routes, // `routes: routes` 的缩写
})

router.beforeEach((to,from,next) => {
  // ...
  // 返回 false 以取消导航
  console.log('to:',to,'from:',from);
  next()
  return to
})

  export default router